//
//  UILabel+CEAttributStr.m
//  ContinueEducation
//
//  Created by 迟建国 on 2018/7/23.
//  Copyright © 2018年 CE. All rights reserved.
//

#import "UILabel+CEAttributStr.h"

@implementation UILabel (CEAttributStr)

- (void)getAttributeLableWithStr:(NSString *)string color:(UIColor *)color range:(NSRange)range{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
//    [str setTextColor:color font:kFont(12) space:0 range:range];
    
    self.attributedText =str;
}
- (void)getAttributeLableEndTimeWithStr:(NSString *)string color:(UIColor *)color range:(NSRange)range{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
//    [str setTextColor:color font:kFont(14) space:15 range:range];
    
    self.attributedText =str;
}
- (void)getAttributeLableNoSpaceWithStr:(NSString *)string color:(UIColor *)color rangeStr:(NSString *)rangeStr{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange range = [[str string] rangeOfString:rangeStr];

    [str addAttribute:NSForegroundColorAttributeName value:color range:range];
//    [str setStrColor:color range:NSRangeFromString(rangeStr)];
    self.attributedText =str;

}
- (void)getAttributeLableWithStr:(NSString *)string color:(UIColor *)color range1:(NSRange)range1 range2:(NSRange)range2{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];

    [str setStrColor:color range:range1];
    [str setStrColor:color range:range2];
    [str setTextSpace:10 range:NSMakeRange(0, string.length)];
    
    self.attributedText =str;

}
- (void)showHTMLWith:(NSString *)str{
    if (!IsStrEmpty(str)) {
        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        self.attributedText = attrStr;
    }
}


- (void)getAttributeLableColorWithStr:(NSString *)str Color:(UIColor *)color range:(NSRange)range{
    NSMutableAttributedString *attributStr = [[NSMutableAttributedString alloc] initWithString:str];
    [attributStr addAttribute:NSForegroundColorAttributeName value:color range:range];
    self.attributedText = attributStr;
}

- (void)getAttributeLableSpaceWithStr:(NSString *)string Space:(CGFloat)space{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
    [str setTextSpace:space range:NSMakeRange(0, string.length)];
    self.attributedText =str;
}
@end
